********************************************************************************
*                                                                              *
*                         IHG Descriptive Statistics                           *
*                                                                              *
********************************************************************************

cd "H:\"

// First and last year of observation
global minyear = 2009
global maxyear = 2020


// Variable list for fixed effects regressions
global xvar robots_tmin4 robots_tmin3 robots_tmin2 robots_tmin1 robots_t0 robots_t1 robots_gt2
global feweightvar hoursworked09
global fecvar beid sbi4#year mun#year c.logvalueaddedpworker09#year c.logworkers09#year

global descrit

use "Robots and Workers\Data\IHG_panel_$minyear$maxyear.dta", clear

////////////////////////////////////////////////////////////////////////////////
////////////////////////HISTOGRAMS FOR EU AND NON EU TRADE//////////////////////
////////////////////////////////////////////////////////////////////////////////

* Create Figure A1

putexcel set "Robots and Workers\Results\Figures.xlsx", modify sheet(Histograms)
serset drop _all
drop if imp_robots ==0
g logimp_robots = ln(imp_robots)
histogram logimp_robots, start(0) width(0.5)

preserve 
	histogram logimp_robots, start(0) width(0.5)
	graph save "Graph" "H:\Robots and Workers\Results\Graph.gph", replace
	clear
	graph use "H:\Robots and Workers\Results\Graph.gph"
	serset dir
	serset use
	export excel using "H:\Robots and Workers\Results\Figures.xlsx", sheet("Histograms") sheetmodify cell(S25) firstrow(variables)
	putexcel S25 = "Log of robot imports (raw IHG data)"
	putexcel T25 = ""
	putexcel U25 = ""
restore

preserve 
	histogram logimp_robots, start(0) width(0.5), if imp_tot>1200000 & EUthreshold==1
	graph save "Graph" "H:\Robots and Workers\Results\Graph.gph", replace
	clear
	graph use "H:\Robots and Workers\Results\Graph.gph"
	serset dir
	serset use
	export excel using "H:\Robots and Workers\Results\Figures.xlsx", sheet("Histograms") sheetmodify cell(W25) firstrow(variables)
	putexcel W25 = "Log of robot imports (above EU threshold)"
	putexcel X25 = ""
	putexcel Y25 = ""
restore

preserve 
	histogram logimp_robots, start(0) width(0.5), if imp_tot<1200000 | EUthreshold==0
	graph save "Graph" "H:\Robots and Workers\Results\Graph.gph", replace
	clear
	graph use "H:\Robots and Workers\Results\Graph.gph"
	serset dir
	serset use
	export excel using "H:\Robots and Workers\Results\Figures.xlsx", sheet("Histograms") sheetmodify cell(AA25) firstrow(variables)
	putexcel AA25 = "Log of robot imports (below EU threshold)"
	putexcel AB25 = ""
	putexcel AC25 = ""
restore


